package com.fare.taluo.application.impl.freight;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.hbase.filter.Filter;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fare.taluo.application.freight.FreightMonitorShowsApplication;
import com.fare.taluo.core.domain.analyse.monitor.FreightMonitorSettingsEntity;
import com.fare.taluo.vo.freight.FreightMonitorSettingsVO;
import com.fare.taluo.vo.freight.FreightMonitorShowsVO;

@Transactional
@Scope("singleton")
@Service("freightMonitorShowsApplication")
public class FreightMonitorShowsApplicationImpl implements FreightMonitorShowsApplication{

	@Override
	public List<FreightMonitorSettingsVO> findCityList(String currentUser) throws Exception {
		List <FreightMonitorSettingsVO>  volist=new ArrayList<FreightMonitorSettingsVO>();
		FreightMonitorSettingsEntity freightMonitorEntity = new FreightMonitorSettingsEntity();
		List<FreightMonitorSettingsEntity> entitylist=freightMonitorEntity.findFreightMonitorAll(currentUser);
		if(entitylist !=null && entitylist.size()>0){
			for(FreightMonitorSettingsEntity entity:entitylist){
				FreightMonitorSettingsVO vo=new FreightMonitorSettingsVO();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
				vo.setId(entity.getId());
				vo.setFromCity(entity.getFromCity());
				vo.setToCity(entity.getToCity());
				vo.setAirLine(entity.getFromCity()+"-"+entity.getToCity());
				vo.setDepartDate(entity.getDepartDate());
				vo.setDepartDateString(sdf.format(entity.getDepartDate()));
				vo.setFlightNumber(entity.getFlightNumber());
				vo.setOpDate(entity.getOpDate());
				vo.setFromCode(entity.getFromCode());
				vo.setToCode(entity.getToCode());
				vo.setAreaCode(entity.getAreaCode());
				vo.setHbaseKey(entity.getHbaseKey());
				volist.add(vo);
			}
		}
		return volist;
	}

	@Override
	public List<FreightMonitorShowsVO> earchChannel(String tableName,String startRowKey, String endRowKey, List<Filter> filters)throws Exception {
		return null;
	}

	@Override
	public List<FreightMonitorSettingsVO> findByLine(Long id) {
		List <FreightMonitorSettingsVO>  volist=new ArrayList<FreightMonitorSettingsVO>();
		FreightMonitorSettingsEntity freightMonitorEntity = new FreightMonitorSettingsEntity();
		List<FreightMonitorSettingsEntity> entitylist=freightMonitorEntity.findByLine(id);
		if(entitylist !=null && entitylist.size()>0){
			for(FreightMonitorSettingsEntity entity:entitylist){
				FreightMonitorSettingsVO vo=new FreightMonitorSettingsVO();
//				vo.setId(entity.getId());
				vo.setFromCity(entity.getFromCity());
				vo.setToCity(entity.getToCity());
				vo.setAirLine(entity.getFromCity()+"-"+entity.getToCity());
				vo.setDepartDate(entity.getDepartDate());
				vo.setFlightNumber(entity.getFlightNumber());
				vo.setOpDate(entity.getOpDate());
				vo.setFromCode(entity.getFromCode());
				vo.setToCode(entity.getToCode());
				vo.setAreaCode(entity.getAreaCode());
				vo.setHbaseKey(entity.getHbaseKey());
				volist.add(vo);
			}
		}
		return volist;
	}

	@Override
	public FreightMonitorSettingsVO getMonitorById(Long id) {
		FreightMonitorSettingsVO vo = new FreightMonitorSettingsVO();
		FreightMonitorSettingsEntity fo=new FreightMonitorSettingsEntity().getMonitorsById(id);
		if(fo !=null){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			vo.setFromCity(fo.getFromCity());
			vo.setToCity(fo.getToCity());
			vo.setDepartDateString(sdf.format(fo.getDepartDate()));
			vo.setOpDateString(sdf.format(fo.getOpDate()));
			vo.setFlightNumber(fo.getFlightNumber());
			vo.setFromCode(fo.getFromCode());
			vo.setToCode(fo.getToCode());
			vo.setAreaCode(fo.getAreaCode());
			vo.setHbaseKey(fo.getHbaseKey());
			vo.setId(fo.getId());
		}
		return vo;
	}

}
